<?php
/**
 * Message Target 
 * 
 * Users List
 */
use Doctrine\DBAL\Connection;
use Fox\Html\Block;

$grid = Xview::instance()->component('users','groupsUsers');
$ajax = Xview::instance()->val('xvtrs',false);
$return = Xview::instance()->val('return',false);
if($ajax && !$return)
{
	$uniqueData = null;
	$data = $grid->get();
	if(is_array($data['gTarget']))
	{
		foreach($data['gTarget'] as $key => $line)
		{
			if(empty($line['idusr']))
				continue;
			$uniqueData[$line['idusr']] = $line;
		}
	}
	$codes = Xview::instance()->val('codes');
	if(is_array($codes))
	{
		$finder = new User();
		$users = $finder->find(new Fox\Dao\SqlFragment('idusr IN (?)',array($codes),array(Connection::PARAM_INT_ARRAY)));
		foreach($users as $user)
		{
			$data = $user->getData();
			$uniqueData[$user->getId()] = $data;
		}
	}
	$grid->initialize($uniqueData);
	echo $grid->display();
}
else
{
	$block = new Block('bTarget');
	$block->add($grid);
	return $block;
}